package com.wxsong.authplatform.authweb.dao.role;

import com.wxsong.authplatform.authweb.dao.BaseDao;
import com.wxsong.authplatform.authweb.model.authority.Authority;
import com.wxsong.authplatform.authweb.model.role.Role;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class RoleDao extends BaseDao {

    public Role getByName(String userName){
        return this.getSqlSession().selectOne("RoleMap.selectByRoleName", userName);
    }

    public Role getById(Long id){
        return this.getSqlSession().selectOne("RoleMap.selectById", id);
    }

    public List<Role> list(int from, int pageSize, Map<String, Object> paramMap){
        paramMap.put("from", from);
        paramMap.put("size", pageSize);
        return this.getSqlSession().selectList("RoleMap.selectList", paramMap);
    }

    public Long count(Map<String, Object> paramMap){
        return this.getSqlSession().selectOne("RoleMap.selectCount", paramMap);
    }

    public int add(Role users){
        return this.getSqlSession().insert("RoleMap.insertRole", users);
    }

    public int update(Map paramMap){
        return this.getSqlSession().update("RoleMap.updateRole", paramMap);
    }

    public int delete(Long[] ids){
        return this.getSqlSession().delete("RoleMap.deleteRole", ids);
    }

    public List<Authority> hasAuths(Long[] longIds) {
        return this.getSqlSession().selectList("AuthorityMap.selectHasAuths", longIds);
    }

    public List<Authority> noAuths(Long[] longIds) {
        return this.getSqlSession().selectList("AuthorityMap.selectNoAuths", longIds);
    }

}
